package com.spring.demo3.eg3;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author vhans
 */
public class DefaultMethodInfo implements IMethodInfo {

    private Class<?> targetClass;

    public DefaultMethodInfo(Class<?> targetClass) {
        this.targetClass = targetClass;
    }

    @Override
    public int methodCount() {
        return this.targetClass.getDeclaredMethods().length;
    }

    @Override
    public List<String> methodNames() {
        Method[] methods = this.getTargetClass().getDeclaredMethods();
        return  Arrays.stream(methods).map(Method::getName).collect(Collectors.toList());
    }

    public Class<?> getTargetClass() {
        return targetClass;
    }

    public void setTargetClass(Class<?> targetClass) {
        this.targetClass = targetClass;
    }
}
